package com.hong.springboot.config;

import com.sproutsocial.nsq.Subscriber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class NsqConsumer {

    //topic
    @Value("${springboot.nsqmq.topic_user}")
    private String topic;
    //channel
    @Value("${springboot.nsqmq.channel}")
    private String channel;

    @Value("${springboot.nsqmq.host}")
    private String lookupHosts;

    //消息费
    @Autowired
    private MessageCallback  messageCallback;

    private Subscriber subscriber;

    @PostConstruct
    public void init(){
        subscriber = new Subscriber(lookupHosts);
        subscriber.subscribe(topic,channel,messageCallback::onMessage);
    }
}